package com.example.lots_of_demo.security;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author : LZJ
 * @description : code for LZJ
 * @date : 2021/2/13
 */
@Component("myRestAuthenticationEntryPoint")
public class MyRestAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
        response.setStatus(403);
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().append("{\"code\":0,\"msg\":\"未登录，请先登录!\",\"data\":\"success\"}");
    }
}
